using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for ScriptsAdaptor.
	/// </summary>
	public class ScriptsAdaptor : Adaptor, IRefreshable
	{
    private ScriptCollection scripts;
		public ScriptsAdaptor(ScriptCollection scripts)
		{
      this.scripts = scripts;
		}

    public override string Text
    {
      get
      {
        return "Scripts (" + scripts.Count + ")";
      }
    }

    public override object Object
    {
      get
      {
        return scripts;
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 31;
      }
    }

    public override void AddChildren(TreeNode node)
    {
      foreach (Script script in scripts)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(new ScriptAdaptor(script));
        node.Nodes.Add(childNode);
      }      
    }

    public override Control GetRenderer()
    {
      ScriptsControl control = new ScriptsControl();
      control.LoadScripts(scripts);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    #region IRefreshable Members

    public void Refresh()
    {
      scripts.Refresh();
    }

    #endregion
  }
}
